package cn.rdq.iknesssystem.controller;

import cn.rdq.api.dto.EpisodeDto;
import cn.rdq.api.po.Episode;
import cn.rdq.api.vo.EpisodeVo;
import cn.rdq.common.CommonResult;
import cn.rdq.iknesssystem.service.EpisodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/episode")
public class EpisodeController {

    @Autowired
    private EpisodeService episodeService;

    @PostMapping("/list")
    public CommonResult list(@RequestBody EpisodeVo episodeVo) {
        List<EpisodeDto> listEpisode = episodeService.listEpisode(episodeVo);
        return CommonResult.success().pageSuccess(listEpisode);
    }

    @PostMapping("/update")
    public CommonResult updateEpisode(@RequestBody Episode episode) {
        boolean b = episodeService.updateById(episode);
        return CommonResult.success();
    }

    @PostMapping("/save")
    public CommonResult saveEpisode(@RequestBody Episode episode) {
        episodeService.saveEpisode(episode);
        return CommonResult.success();
    }

    @GetMapping("/del/{id}")
    public CommonResult delete(@PathVariable Long id) {
        episodeService.deleteEpisode(id);
        return CommonResult.success();
    }

}
